import * as types from '../action-types'
import {push} from 'connected-react-router'
import {reg,login} from '../../api/session'


interface setSessionAction{
  type: string,
  payload:any
}

export type Action = setSessionAction 
export default {
  reg (user) {
    return function(dispatch,getState){
      reg(user).then(res=>{
        if(res.code === 0){
          // dispatch({type:types.SET_SESSION,payload:res.data})
          dispatch(push('/login'))
        }
      })
    }
   },
   login (user) {
    return function(dispatch,getState){
      login(user).then(res=>{
        if(res.code === 0){
          dispatch({type:types.SET_SESSION,payload:res.data})
          dispatch(push('/profile'))
        }
      })
    }
   },
 
 }